﻿namespace DimensionsHelper.Client.WinUi.Models;

public sealed partial class MessageModel : ObservableObject, IMessage
{
    public MessageModel(IProjectTask owner)
    {
        Owner = owner;
    }


    public IProjectTask Owner { get; }


    [ObservableProperty]
    public partial Uri? LocalUri { get; set; }


    [ObservableProperty]
    public partial string Section { get; set; } = string.Empty;


    [ObservableProperty]
    public partial string Message { get; set; } = string.Empty;


    [ObservableProperty]
    public partial double Progress { get; set; } = double.NaN;


    [ObservableProperty]
    public partial string LocalDirectory { get; set; } = string.Empty;


    [ObservableProperty]
    public partial MessageType Type { get; set; } = MessageType.Information;


    [ObservableProperty]
    public partial bool WithProgress
    {
        get;
        set;
    }


    partial void OnLocalDirectoryChanged(string value)
    {
        string escaped = StringHelper.ToLocalPathUriString(value);
        if (Uri.TryCreate(escaped, UriKind.Absolute, out Uri? uri))
        {
            LocalUri = uri;
        }
    }
}